package com.imooc.portal.web;

import com.imooc.business.DateMetaBusiness;
import com.imooc.business.QueryAssetBusiness;
import com.imooc.business.QueryTableBusiness;
import com.imooc.module.query.request.HttpQueryDataRequest;
import com.imooc.module.query.response.QueryDataResponse;
import com.imooc.module.reponse.AssetDataResponse;
import com.imooc.module.reponse.QueryDateMetaResponse;
import com.imooc.module.reponse.RestResult;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Tim
 * @Description:
 * @Version 1.0
 */
@RequestMapping("/data-center/data")
@RestController
public class DataController {

    @Setter(onMethod_ = @Autowired)
    private QueryTableBusiness queryBusiness;

    @Setter(onMethod_ = @Autowired)
    private DateMetaBusiness dateMetaBusiness;

    @Setter(onMethod_ = @Autowired)
    private QueryAssetBusiness queryAssetBusiness;

    @PostMapping("/queryTable")
    public RestResult<QueryDataResponse> queryTable(@RequestBody HttpQueryDataRequest request) {
        return RestResult.success(queryBusiness.query(request));
    }

    /**
     * 时间维度元数据查询
     */
    @GetMapping(value = "/queryDateMetaData")
    public QueryDateMetaResponse queryDateMetaData() {
        return dateMetaBusiness.queryDateMetaData();
    }

    /**
     * 时间维度周期数据查询
     */
    @GetMapping(value = "/queryDatePeriodData")
    public QueryDateMetaResponse queryDatePeriodData(@RequestParam Integer periodType) {
        return dateMetaBusiness.queryDatePeriodData(periodType);
    }

    /**
     * 资产目录
     */
    @GetMapping("/queryAsset")
    public RestResult<AssetDataResponse> queryAsset() {
        return RestResult.success(queryAssetBusiness.queryAsset());
    }

    /**
     * 资产明细数据
     */
    @GetMapping("/queryAssetItem")
    public RestResult<AssetDataResponse> queryAssetItem(String ruleId) {
        return RestResult.success(queryAssetBusiness.queryAssetItem(ruleId));
    }
}
